package com.lifeng.controller;

import brave.Span;
import brave.Tracer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created by lifeng on 2019/3/18.
 */
@RestController
public class UserController {
    private static final Logger log = LoggerFactory.getLogger(UserController.class);
    @Autowired
    public RestTemplate restTemplate;
    @Autowired
    private Tracer tracer; //用于访问Spring Cloud Sleuth跟踪信息
    @RequestMapping("/user")
    public String getUser(String id){
        Span span = null;
        try {
            span = tracer.currentSpan();
            span.tag("id", id);
            log.info("tracerId:"+span.context().traceIdString());
            return restTemplate.getForObject("http://127.0.0.1:8109/getBlog?id=" + id, String.class);
        }catch (Exception e){
            log.error("",e);
        }
        return null;
    }
}
